﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;
using System.ComponentModel.Design;
using Zero.UControl.Base.Helper.Base.UAdorner;

namespace Zero.UControl.Base.Helper.Base
{
    internal class DeleteCommand : IDrawingCommand
    {

        private readonly Canvas _c;
        private readonly UIElement _e;
        private readonly SelectionService _s;
        private int _idx;

        public DeleteCommand(Canvas c, UIElement e, SelectionService s)
        {
            _c = c;
            _e = e;
            _s = s;
        }

        public void Execute()
        {
            _idx = _c.Children.IndexOf(_e);
            if (_idx >= 0) _c.Children.RemoveAt(_idx);
            _s.Detach(_e);
        }

        public void UnExecute()
        {
            if (_idx >= 0)
            {
                _c.Children.Insert(_idx, _e);
                _s.Attach(_e);
            }
        }
    }

}
